using System;
using System.Windows.Forms;
using DataModel;
using DevExpress.XtraEditors;
using RitaReports.Travels;

namespace RitaReports.Training
{
    public partial class TrainingFilter : XtraUserControl, IReportFilter
    {
        public TrainingFilter()
        {
            InitializeComponent();
        }


        #region IReportFilter Members

        public Control FilterControl
        {
            get { return this; }
        }

        public IReportFilterConditionds FilterConditionds
        {
            get
            {
                TravelsFilterConditionds conditionds = new TravelsFilterConditionds();

                if (deDateFrom.EditValue != null || deDateTo.EditValue != null)
                {
                    DateTime? from = null;
                    DateTime? to = null;

                    if (deDateFrom.EditValue != null)
                    {
                        from = (DateTime) deDateFrom.EditValue;
                    }

                    if (deDateTo.EditValue != null)
                    {
                        to = (DateTime) deDateTo.EditValue;
                    }

                    conditionds.Date = new Range<DateTime?>(from, to);
                }

                return conditionds;
            }
        }

        #endregion

        private void btnClear_Click(object sender, EventArgs e)
        {
            deDateFrom.EditValue = null;
            deDateTo.EditValue = null;
        }
    }
}